﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using NextCMS.Models;

public partial class WebAdmin_WebAdmin : System.Web.UI.MasterPage
{
    public int SiteId
    {
        get
        {
            return Convert.ToInt32(Session["SiteId"]);
        }
    }
    public string SiteName
    {
        get
        {
            return Session["SiteName"] == null ? CommonMethods.GetSiteName(SiteId) : Convert.ToString(Session["SiteName"]);
        }
    }
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindDropDowns();
            lnkSelectedSite.Text = SiteName;
        }
    }
    void BindDropDowns()
    {
        using (SiteLanguagesHelper helper = new SiteLanguagesHelper())
        {
            IEnumerable<SiteLanguageModel> lstLang=helper.GetAllBySiteId(SiteId);
            DDLSiteLanguages.DataSource = lstLang;
            DDLSiteLanguages.DataTextField = "LangName";
            DDLSiteLanguages.DataValueField = "Id";
            DDLSiteLanguages.DataBind();
            DDLSiteLanguages.SelectedValue = Convert.ToString(Session["LangId"]);
            if (lstLang.Count() == 0)
            {
                DDLSiteLanguages.Items.Insert(0, new ListItem("Select", "0"));
            }
            else
            {
                Session["LangId"] = Convert.ToInt32(DDLSiteLanguages.SelectedValue);
            }
        }
    }
    protected void DDLSiteLanguages_SelectedIndexChanged(object sender, EventArgs e)
    {
        Session["LangId"] = DDLSiteLanguages.SelectedValue;
        Response.Redirect(Request.Url.PathAndQuery);
    }
}
